﻿@{
    Layout = "~/Views/Shared/_LayuiLayout.cshtml";
}
<form class="layui-form layui-form-pane">
    <div style="padding:18px;">
        @foreach (var item in ViewBag.AllRoleList)
            {
            <input type="checkbox" value="@item.Id" title="@item.RoleName"
                   lay-filter="isEnable" @(item.IsEnable ? "checked" : "") />
        }
    </div>
    <div class="layui-form-item" align="center">
        <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:layer_close();parent.reload();">关闭</button>
    </div>
</form>
@section scripts{
    <script>
        layui.use(['form', 'layer', 'upload'], function () {
            var form = layui.form,
                layer = layui.layer,
                upload = layui.upload,
                $ = layui.$;

            //监听复选框勾选
            form.on('checkbox(isEnable)', function (obj) {
                console.log(obj);
                $.post('@Url.Action("SetUserRole", "User")'
                        , { Id: @ViewBag.UserId, RoleId: obj.value, check: obj.elem.checked }
                        , function (msg) {
                            if (msg.Success == true) {
                                layer.msg(msg.Message, { icon: 1, time: 1000 });
                            } else {
                                layer.alert(msg.Message, { icon: 2 });
                            }
                        });
            });
        });
    </script>
}